/**
* @description: 861. 翻转矩阵后的得分
* @author hewei
* @date 2022/9/9 14:56
* @version 1.0
*/

public class MatrixScore {

    public static void main(String[] args) {
        int[][] nums = {{0, 0, 1, 1}, {1, 0, 1, 0}, {1, 1, 0, 0}};
        System.out.println(new MatrixScore().matrixScore(nums));
    }

    public int matrixScore(int[][] grid) {
        for (int i = 0; i < grid.length; i++) {
            if (grid[i][0] == 0) {
                for (int j = 0; j < grid[i].length; j++) {
                    if (grid[i][j] == 0) {
                        grid[i][j] = 1;
                    } else grid[i][j] = 0;
                }
            }
        }
        for (int i = 0; i < grid[0].length; i++) {
            int count = 0;
            for (int j = 0; j < grid.length; j++) {
                if (grid[j][i] == 1) ++count;
            }
            if (count <= grid.length / 2) {
                for (int j = 0; j < grid.length; j++) {
                    if (grid[j][i] == 0) {
                        grid[j][i] = 1;
                    } else grid[j][i] = 0;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < grid.length; i++) {
            int temp = 0;
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] == 1) temp += Math.pow(2, grid[0].length - j - 1);
            }
            ans += temp;
        }
        return ans;
    }
}
